package com.niit.servlet;

import com.niit.pojo.downFile;
import com.niit.service.HadoopService;
import com.niit.service.impl.HadoopServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @author Liu
 * @date 2022/2/13 13:12
 **/
@WebServlet(name = "downloadServlet", value = "/displayFileServlet")
public class displayFileServlet extends HttpServlet {
    public void init(HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HadoopService hadoopService = new HadoopServiceImpl();
        List<downFile> downFiles = hadoopService.displayFiles();
        req.setAttribute("fileList", downFiles);
        req.getRequestDispatcher("/pages/downloadPage.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
